function subsets(nums: number[]): number[][] {
  const n = nums.length;
  const ans: number[][] = [];
  const chosen: number[] = [];
  recursion(0);
  return ans;

  function recursion(i: number) {
    if (i === n) {
      ans.push([...chosen]);
      return;
    }
    recursion(i + 1);
    chosen.push(nums[i]);
    recursion(i + 1);
    chosen.pop();
  }
};